;;; memo-mode.el --- Custom major mode with colored faces

;; 定义关键字
(defvar memo-key1
  '("NA" "NO" "No" "Note" "attention" "false" "imp" "important" "later" "note" "notice" "og" "ongoing" "参考点" "已总结" "未总结" "注" "注意" "详见专题"))

(defvar memo-key2
  '("Figure" "abort" "cancelledtodo" "cxtodo" "discussed" "done" "donetodo" "duplicated" "figure" "formula" "movedtodo" "no" "nomoretodo" "noneed" "notnow" "open" "pause" "pic" "公式" "图"))

(defvar memo-key3
  '("..." ">>>" "?" "digest" "failedtodo" "nouse" "ogtodo" "ongoingtodo" "torephrase" "torfz"))

(defvar memo-key4
  '("delayed_todo" "detodo" "todo" "TODO"))

;; 定义自定义 face
(defface memo-comment-face
  '((t (:foreground "#e13e3f")))
  "comment face"
  :group 'my-memo-mode)

(defface memo-key1-face
  '((t (:foreground "#c1252d" :background "#d6d823")))
  "key1 face"
  :group 'my-memo-mode)

(defface memo-key2-face
  '((t (:foreground "#aa8000")))
  "key2 face"
  :group 'my-memo-mode)

(defface memo-key3-face
  '((t (:foreground "#12c2d2")))
  "key3 face"
  :group 'my-memo-mode)

(defface memo-key4-face
  '((t (:foreground "#d7dce3" :background "#bc42de")))
  "key4 face"
  :group 'my-memo-mode)

(defface memo-block-comment-face
  '((t (:foreground "#b7659c" :background "#f1ecee")))
  "block comment face"
  :group 'my-memo-mode)

(defface memo-string-face
  '((t (:foreground "#1cb01c")))
  "string face"
  :group 'my-memo-mode)

(defface memo-number-face
  '((t (:foreground "#f971bb")))
  "number face"
  :group 'my-memo-mode)

;; 主模式定义
(define-derived-mode memo-mode prog-mode "Memo"
  "Major mode with custom colored faces."

  ;; 禁用 hideshow
  (when (fboundp 'hs-minor-mode)
    (hs-minor-mode -1))

  ;; 设置注释
  (setq-local comment-start "#")
  (setq-local comment-end "")

  ;; 字体锁定规则
  (setq-local
   font-lock-defaults
   `((
      ;; 使用自定义 face 的规则
      (,(regexp-opt memo-key1 'symbols) . 'memo-key1-face)
      (,(regexp-opt memo-key2 'symbols) . 'memo-key2-face)
      (,(regexp-opt memo-key3 'symbols) . 'memo-key3-face)
      (,(regexp-opt memo-key4 'symbols) . 'memo-key4-face)
      ("?" . 'memo-key3-face)
      ("\\..." . 'memo-key3-face)
      ("#.*" . 'memo-comment-face)
      ("\"[^\"]*\"" . 'memo-string-face)
      ;; ("\"aaa\"" . 'memo-string-face)
      ("'[^']*'" . 'memo-string-face)
      ("[0-9]+\\.?[0-9]*" . 'memo-number-face)
      )
    t
    t
    ))
  )

;; 文件关联
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.memo\\'" . memo-mode))

(provide 'memo-mode)
